home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / unarced / utilities / emulators / apple][ / prodos.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  2KB  |  152 lines

  1. /*
  2.  *  a2, an Apple II emulator in C
  3.  *  (c) Copyright 1990 by Rich Skrenta
  4.  *
  5.  *  Command line interface written by Tom Markson
  6.  *
  7.  *  Distribution agreement:
  8.  *
  9.  *    You may freely copy or redistribute this software, so long
  10.  *    as there is no profit made from its use, sale, trade or
  11.  *    reproduction.  You may not change this copyright notice,
  12.  *    and it must be included prominently in any copy made.
  13.  *
  14.  *  Send emulator related mail to:  skrenta@blekko.commodore.com
  15.  *                    skrenta@blekko.uucp
  16.  */
  17.  
  18.  
  19. #include    <stdio.h>
  20. #include    "a2.h"
  21.  
  22.  
  23. #define        BSIZE    512        /* block size */
  24. #define        D1SIZE    280        /* Size of disk 1 */
  25. #define        D2SIZE    1024        /* Size of disk 2 */
  26.  
  27.  
  28. /*
  29.  *  Prodos to DOS 3.3 block mapping
  30.  */
  31.  
  32. int conv1[] = { 0x00, 0x0D, 0x0B, 0x09, 0x07, 0x05, 0x03, 0x01 };
  33. int conv2[] = { 0x0E, 0x0C, 0x0A, 0x08, 0x06, 0x04, 0x02, 0x0F };
  34.  
  35.  
  36.  
  37. proformat()
  38. {
  39.  
  40.     if (write_prot[drive]) {
  41.         C = 1;
  42.         A = 0x2B;        /* Write protected */
  43.         return;
  44.     }
  45.  
  46.     C = 0;
  47.     A = 0;
  48. }
  49.  
  50.  
  51. proread()
  52. {
  53. int block;
  54. unsigned short ptr;
  55. int track, sector;
  56. char s[50];
  57.  
  58.     block = join(mem[0x46], mem[0x47]);
  59.     ptr = join(mem[0x44], mem[0x45]);
  60.  
  61.     sprintf(s, "proread b=%d", block);
  62.     info(s);
  63.  
  64.     track = block / 8;
  65.     sector = conv1[block % 8];
  66.  
  67.     read_disk(track, sector, &mem[ptr]);
  68.     ptr += 0x100;
  69.  
  70.     sector = conv2[block % 8];
  71.     read_disk(track, sector, &mem[ptr]);
  72.  
  73.     C = 0;
  74.     A = 0;
  75. }
  76.  
  77.  
  78. prowrite()
  79. {
  80. int block;
  81. unsigned short ptr;
  82. int track;
  83. int sector;
  84. char s[50];
  85.  
  86.     if (write_prot[drive]) {
  87.         C = 1;
  88.         A = 0x2B;        /* Write protected */
  89.         return;
  90.     }
  91.  
  92.     block = join(mem[0x46], mem[0x47]);
  93.     ptr = join(mem[0x44], mem[0x45]);
  94.  
  95.     sprintf(s, "prowrite b=%d", block);
  96.     info(s);
  97.  
  98.     track = block / 8;
  99.     sector = conv1[block % 8];
  100.  
  101.     write_disk(track, sector, &mem[ptr]);
  102.     ptr += 0x100;
  103.  
  104.     sector = conv2[block % 8];
  105.     write_disk(track, sector, &mem[ptr]);
  106.  
  107.     C = 0;
  108.     A = 0;
  109. }
  110.  
  111.  
  112. prostatus()
  113. {
  114.  
  115.     C = 0;
  116.     A = 0;
  117.     Y = high(D1SIZE);
  118.     X = low(D1SIZE);
  119. }
  120.  
  121.  
  122. prodos()
  123. {
  124.  
  125.     if (mem[0x43] < 0x80)
  126.         drive = 0;
  127.     else
  128.         drive = 1;
  129.  
  130.     if (disk[drive] < 0) {
  131.         C = 1;
  132.         A = 0x27;        /* IO Error */
  133.  
  134.     } else switch (mem[0x42]) {
  135.         case 0: 
  136.             prostatus();
  137.             break;
  138.         case 1:
  139.             proread();
  140.             break;
  141.         case 2:
  142.             prowrite();
  143.             break;
  144.         case 3:
  145.             proformat();
  146.             break;
  147.     }
  148.  
  149.     DO_RTS;
  150. }
  151.  
  152.